/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package beans.dao;

import core.APersistenceManager;
import core.ILeagueDAO;
import java.math.BigDecimal;
import java.util.List;
import java.util.Set;
import persistence.*;
import validators.LeagueValidator;

/**
 *
 * @author Ivan
 */
public class LeagieDAO extends APersistenceManager<League> implements ILeagueDAO {

    public LeagieDAO() {
        super(League.class,new LeagueValidator());
    }

    @Override
    public League getLeagueByGame(int idGame) {
        Game game = getEntityManager().find(Game.class, BigDecimal.valueOf(idGame));
        Tournament tournament = game.getTournamentId();
        return tournament.getLeagueId();
    }

    @Override
    public League getLeagueByTournament(int idTournament) {
        Tournament tournament = getEntityManager().find(Tournament.class, BigDecimal.valueOf(idTournament));
        return tournament.getLeagueId();
    }

    @Override
    public Set<League> getLeaguesByDiscipline(int idDiscipline) {
        Discipline discipline = getEntityManager().find(Discipline.class, BigDecimal.valueOf(idDiscipline));
        return discipline.getLeagueSet();

    }

    @Override
    public Set<League> getLeaguesByOwner(int idUser) {
        SysUser sysUser = getEntityManager().find(SysUser.class, BigDecimal.valueOf(idUser));
        return sysUser.getLeagueSet();
    }

    @Override
    public Team getWinner(int id) {
        League league = getEntityManager().find(League.class, BigDecimal.valueOf(id));
        return league.getWinnerTeamId();
    }  
}
